//index.js
//获取应用实例
const app = getApp()
const util = require("../../utils/util.js")

Page({
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    showResult: false,
    message: '',
    bgColor: 'bg-red',
    time: 0,
    host: ''
  },
  onLoad: function() {
    app.getAuthKey()
  },
  formSubmit: function(e) {
    const me = this;
    const formData = e.detail.value
    const host = formData.host
    const port = formData.port
    if (!host || !port) {
      wx.showToast({
        title: '缺少必填项',
        icon: 'none'
      })
    } else {
      wx.showLoading({
        title: '玩命加载中...',
      })
      wx.request({
        url: app.globalData.host + 'ip/ping',
        method: 'POST',
        data: {host: host, port: port},
        success(res) {
          console.log(res)
          me.setData({
            message: res.data.message,
            bgColor: res.data.status ? 'bg-blue': 'bg-red',
            time: res.data.time,
            host: res.data.host,
            showResult: true
          })
        },complete(res){
          wx.hideLoading()
        }
      })
    }
  }
})